from celery import Celery
from celery.signals import before_task_publish, after_task_publish, task_failure

celery_app = Celery( "clean_data_task", broker="redis://localhost:6379/0", backend="redis://localhost:6379/1" )

@before_task_publish.connect
def handle_before_task_publish(sender=None, headers=None, body=None, **kwargs):
    print(f"任务准备写入 Broker: {sender}")

@after_task_publish.connect
def handle_after_task_publish(sender=None, headers=None, body=None, **kwargs):
    print(f"任务已成功写入 Broker: {sender}")

@task_failure.connect
def handle_task_failure(sender=None, exception=None, **kwargs):
    print(f"任务失败，Redis Backend 异常: {exception}")
